package com.share.design.proxy;

import java.lang.reflect.Proxy;

/**
 * author:caifan
 * date:2020/2/4
 */
public class ProxyClient {
    public static void main(String[] args) {
        Girl girl = new Girl();
        girl.setName("美女");
        Boy2 boy2 = new Boy2(girl);//代理对象
        boy2.giveFlower();

        /**
         * 动态代理
         */
        System.out.println("============");
        GiveGift boy1 = new Boy1(girl);
        DynamicProxy dynamicProxy = new DynamicProxy(boy1);
        GiveGift proxyBoy = (GiveGift) Proxy.newProxyInstance(boy1.getClass().getClassLoader(), boy1.getClass().getInterfaces(), dynamicProxy);
        proxyBoy.giveFlower();
    }
}
